from typing import *
from math import inf


class Solution:

    def maxAbsoluteSum(self, nums: List[int]) -> int:
        mn, mx, ans = 0, 0, 0
        for num in nums:
            mn = mn + num if mn < 0 else num
            mx = mx + num if mx > 0 else num
            ans = max(abs(mn), abs(mx), ans)
        return ans


class Solution:

    def maxAbsoluteSum(self, nums: List[int]) -> int:
        mn, mx, ans = 0, 0, 0
        for num in nums:
            mn = min(mn + num, num)
            mx = max(mx + num, num)
            ans = max(abs(mn), abs(mx), ans)
        return ans


class Solution:

    def maxAbsoluteSum(self, nums: List[int]) -> int:
        tot = ans = mn = mx = 0
        for num in nums:
            tot += num
            ans = max(ans, abs(tot - mx), abs(tot - mn))
            mn = min(mn, tot)
            mx = max(mx, tot)
        return ans